package com.ugoodtech.mdcc.client.service.impl;

import com.mysema.query.BooleanBuilder;
import com.ugoodtech.mdcc.core.domain.CustomerRegularReport;
import com.ugoodtech.mdcc.core.domain.QCustomerRegularReport;
import com.ugoodtech.mdcc.core.repository.CustomerRegularReportRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Component
public class QuartzService {

    @Autowired
    private CustomerRegularReportRepository customerRegularReportRepository;

//    @Scheduled(cron = "0 0/1* * * ?")
//    public void timerToNow() {
//        System.out.println("now time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//    }

//    /**
//     * 每小时判断是否有客户没填满意度 如果24小时没填就推送微信
//     */
//    @Scheduled(cron = "0 0/60 * * * ?")
//    public void pushWeChatMsg() {
//        Long nowTime = System.currentTimeMillis();
//        QCustomerRegularReport qCustomerRegularReport = QCustomerRegularReport.customerRegularReport;
//        BooleanBuilder builder = new BooleanBuilder();
//        builder.and(qCustomerRegularReport.deleted.eq(false));
//        builder.and(qCustomerRegularReport.enabled.eq(true));
//        builder.and(qCustomerRegularReport.customerReport.isNull());
//        List<CustomerRegularReport> customerRegularReportList = (List<CustomerRegularReport>) customerRegularReportRepository.findAll(builder);
//        for (CustomerRegularReport report : customerRegularReportList) {
//            Long creationTime = report.getCreationTime().getTime();
//            Long subTime = nowTime - creationTime;
//            if (subTime == 0) {
//                //todo 微信推送
//            }
//        }
//    }

}
